package com.cy;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class AActivity extends Activity {

    private String TAG = "A_Activity";
    private String strTag = "A";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG, "onCreate: " + strTag);
        setContentView(R.layout.activity_main);
        findViewById(R.id.tv1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(AActivity.this, "222 222", Toast.LENGTH_LONG).show();
            }
        });
        findViewById(R.id.tv2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                show();
            }
        });
        findViewById(R.id.tv3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AActivity.this.startActivity(new Intent(AActivity.this, BActivity.class));
            }
        });
    }

    @Override
    protected void onStart() {
        Log.i(TAG, "onStart: " + strTag);
        super.onStart();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i(TAG, "onRestart: " + strTag);
    }

    @Override
    protected void onResume() {
        Log.i(TAG, "onResume: " + strTag);
        super.onResume();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        Log.i(TAG, "onSaveInstanceState 单参数: " + strTag);
        super.onSaveInstanceState(outState);
    }

    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        Log.i(TAG, "onSaveInstanceState 多参数: " + strTag);
        super.onSaveInstanceState(outState, outPersistentState);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        Log.i(TAG, "onRestoreInstanceState 单参数: " + strTag);
        super.onRestoreInstanceState(savedInstanceState);
    }

    public void onRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState) {
        Log.i(TAG, "onRestoreInstanceState 多参数: " + strTag);
        super.onRestoreInstanceState(savedInstanceState, persistentState);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        Log.i(TAG, "onConfigurationChanged: " + strTag);
        super.onConfigurationChanged(newConfig);
    }

    @Override
    protected void onPause() {
        Log.i(TAG, "onPause: " + strTag);
        super.onPause();
    }

    @Override
    protected void onStop() {
        Log.i(TAG, "onStop: " + strTag);
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        Log.i(TAG, "onDestroy: " + strTag);
        super.onDestroy();
    }


    private void show() {
        //弹出对话框.
        AlertDialog.Builder builder = new AlertDialog.Builder(AActivity.this);
        builder.setTitle("列表对话框!");
        builder.setIcon(R.mipmap.ic_launcher);
        builder.setItems(new String[]{"0111111"}, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                switch (i) {
                    case 0:
                        Toast.makeText(AActivity.this, "123", Toast.LENGTH_LONG).show();
                        break;
                }
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
    }
}
